package com.baizhi.config.log;

import cn.hutool.json.JSONUtil;
import com.baizhi.entity.CmfzLog;
import com.baizhi.mapper.CmfzLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;

@Component
public class LogMqListener {

    @Autowired
    private CmfzLogMapper cmfzLogMapper;

    @JmsListener(destination = "cmfz-log")
    public void logMqListener(Message message) throws JMSException {

        TextMessage textMessage=(TextMessage)message;
        String text = textMessage.getText();

        CmfzLog cmfzLog = JSONUtil.toBean(text, CmfzLog.class);
        System.out.println(cmfzLog);
        System.out.println("=====================");
        cmfzLogMapper.insert(cmfzLog);
    }
}
